
#include <iostream>
using namespace std;

#include "def.hpp"
#include "math/sphere.hpp"
#include "math/plane.hpp"
#include "math/triangle.hpp"
//#include "math/rect.hpp"
#include "math/cmpd_rt_object.hpp"

#include "math/light.hpp"

#include "sys/timer.hpp" 
#include "math/scene.hpp"
#include "math/checker.h"

Timer myTimer; 

int main(int argc, char**argv)
{
	using namespace Defined;
	//My light
	Light myLight(Point3D(0, height/2-300,-300), White, 1.0);
	Light myLight2(Point3D(width, height/2-300, -300), White, 0.5);
	Light myLight3(Point3D(width/2, height/2, -300), White, 0.1);

	//Creating simplest scene
	Sphere mySphere(Point3D(width/2+300,520,100),GlossyGreen,100);
	mySphere.SetName("First Sphere");
	Sphere mySphere2(Point3D(width/2,520,100),GlossyRed,100);
	mySphere2.SetName("Second Sphere");
	Sphere mySphere3(Point3D(width/2-300,520,100),GlossyBlue,100);
	mySphere3.SetName("Third Sphere");
	
	Plane myPlane1(Point3D(200, 620, 200),Point3D(0,620,200),Point3D(200,620,500), GlossyWhite);
	myPlane1.SetName("Plane 1");
	myPlane1.objTex = new Checker(Defined::Red,Defined::Yellow,Vector3D(0.01,0.01,0.01),Vector3D(0,0,0));

	Plane myPlane2(Point3D(0, 0, 350),Point3D(width,0,350),Point3D(width,height,600),NonReflect);
	myPlane2.SetName("Plane 2");
	

	Triangle myTriag(Point3D(width/2-200, height/2-200, 500),Point3D(width/2,height/2,500),Point3D(width/2+200,height/2-200,100),Defined::GlossyGreen);
	Triangle myTriag2(Point3D(width/2+200, height/2-200, 500),Point3D(width/2,height/2,500),Point3D(width/2-200,height/2-200,100), Defined::NonReflect);
	
	CmpdRTobject spheres;
	spheres.SetName("All Spheres");
	
	spheres.Add(&mySphere);
	spheres.Add(&mySphere2);
	spheres.Add(&mySphere3);
	
	CmpdRTobject planes;
	planes.SetName("All planes");
	planes.Add(&myPlane1);
//	planes.Add(&myPlane2);
//	planes.Add(&myTriag);
//	planes.Add(&myTriag2);
		
	Scene myScene;
	myScene.SetName("Main Scene");
	
	myScene.Add(&planes);
	myScene.Add(&spheres);

	myScene.AddLight(&myLight);
	myScene.AddLight(&myLight2);
	myScene.AddLight(&myLight3);

	myTimer.Start(); 

	myScene.Render();

	myTimer.Stop(); 

	cout << "Working time: " << myTimer.GetElapsedTimeInSec() << " sec " << myTimer.GetElapsedTimeInMs() << " ms" << endl;	

   	int x;
	cin >> x;
	return 0;
}
